{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "# Our Deepscaler dataset combines all existing datasets into one.\n",
    "# Leaving out olympiad.json as the dataset is too large, too long to train.\n",
    "datasets = [\"amc\", \"omni_math\", \"aime\", \"still\", \"math\"]\n",
    "\n",
    "data = []\n",
    "for dataset in datasets:\n",
    "    with open(f'../train/{dataset}.json', 'r') as f:\n",
    "        data.extend(json.load(f))\n",
    "\n",
    "len(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from deepscaler.rewards.math_utils.utils import _sympy_parse, _normalize, should_allow_eval\n",
    "\n",
    "# Filter for datapoints that can't be parsed by sympy.\n",
    "filtered_data = []\n",
    "count = 0\n",
    "for entry in data:\n",
    "    answer = entry['answer']\n",
    "    try:\n",
    "        if should_allow_eval(_normalize(answer)):\n",
    "            filtered_data.append(entry)\n",
    "            continue\n",
    "        else:\n",
    "            # print(answer)\n",
    "            count += 1\n",
    "    except Exception as e:\n",
    "        # print(answer)\n",
    "        count += 1\n",
    "\n",
    "count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('./deepscaler.json', 'w') as f:\n",
    "    json.dump(filtered_data, f)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "tsj",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
